package cn.harry.cabinet.model.entity

import androidx.room.Entity
import androidx.room.PrimaryKey
import cn.harry.cabinet.model.enums.Gender
import cn.harry.cabinet.model.enums.UserStatus
import java.util.Date

/**
 * 用户表
 */
@Entity(tableName = "users")
data class User(
    @PrimaryKey(autoGenerate = true)
    val id: Long = 0,
    
    /** 工号 */
    val employeeId: String,
    
    /** 姓名 */
    val name: String,
    
    /** 手机号 */
    val phoneNumber: String,
    
    /** 岗位 */
    val position: String,
    
    /** 性别 */
    val gender: Gender,
    
    /** 状态 启用、禁用 */
    val status: UserStatus,
    
    /** 特征码 */
    val featureCode: String,
    
    /** 密码（4位数字） */
    val password: String = "",
    
    /** 创建时间 */
    val createTime: Date = Date(),
    
    /** 修改时间 */
    val updateTime: Date = Date()
) {
    /**
     * 伴生对象，用于创建User实例
     */
    companion object {
        /**
         * 创建已存在的用户（用于更新）
         */
        fun createExistingUser(id: Int, name: String, employeeId: String, phoneNumber: String): User {
            return User(
                id = id.toLong(),
                employeeId = employeeId,
                name = name,
                phoneNumber = phoneNumber,
                position = "",
                gender = Gender.MALE,
                status = UserStatus.ENABLED,
                featureCode = "",
                password = "",
                createTime = Date(),
                updateTime = Date()
            )
        }
        
        /**
         * 创建新用户（用于插入）
         */
        fun createNewUser(
            name: String, 
            employeeId: String, 
            phoneNumber: String,
            position: String = "",
            gender: Gender = Gender.MALE,
            status: UserStatus = UserStatus.ENABLED,
            featureCode: String = "",
            password: String = ""
        ): User {
            return User(
                employeeId = employeeId,
                name = name,
                phoneNumber = phoneNumber,
                position = position,
                gender = gender,
                status = status,
                featureCode = featureCode,
                password = password,
                createTime = Date(),
                updateTime = Date()
            )
        }
        
        /**
         * 创建用于删除的用户（只需要ID）
         */
        fun createForDelete(id: Int): User {
            return User(id = id.toLong(), "", "", "", "", Gender.MALE, UserStatus.ENABLED, "", "", Date(), Date())
        }
    }
}